<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
    >
      <el-form-item label="流程编号">
        <el-input
          v-model="queryParams.flowNo"
          placeholder="请输入流程编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="开始时间">
        <el-date-picker
          v-model="queryParams.startTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择开始时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="结束时间">
        <el-date-picker
          v-model="queryParams.endTime"
          type="datetime"
          format="yyyy-MM-dd HH:mm:ss"
          value-format="yyyy-MM-dd HH:mm:ss"
          placeholder="请选择结束时间"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
        >搜索</el-button>
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
        >重置</el-button>
      </el-form-item>
    </el-form>
    <el-table
      v-loading="loading"
      :data="initTable"
      :height="tableHeight"
      style="width: 100%"
    >
      <el-table-column
        label="流程单号"
        align="center"
        prop="flowNo"
        width="220"
      ></el-table-column>
      <el-table-column
        label="客户名称+流程名称"
        align="center"
        prop="flowName"
        width="220"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        label="流程类型"
        align="center"
        prop="templateName"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        label="审核状态"
        align="center"
        prop="currStatusName"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        label="发起时间"
        align="center"
        prop="publishTime"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        label="业务发起人"
        align="center"
        prop="creatorNickName"
        :show-overflow-tooltip="true"
      ></el-table-column>
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-view"
            @click="handleView(scope.row)"
          >查看
          </el-button>
        </template>
      </el-table-column>
    </el-table>
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="handleList"
    />
  </div>
</template>

<script>
import { getFlows } from '@/api/processManage/approveForms'
export default {
  // name: 'AlreadyDone',
  data() {
    return {
      total: 0,
      queryParams: {
        flowNo: '',
        startTime: '',
        endTime: '',
        pageNum: 1,
        pageSize: 10,
      },

      //初始化表格
      initTable: [],
      tableHeight: window.innerHeight - 300,
      loading: false,
    }
  },
  mounted() {
    this.handleList()
  },
  methods: {
    handleQuery() {
      this.queryParams.pageNum = 1
      this.handleList()
    },
    resetQuery() {
      this.queryParams = {
        flowNo: '',
        startTime: '',
        endTime: '',
        pageNum: 1,
        pageSize: 10,
      }
      this.handleList()
    },
    handleList() {
      getFlows({
        flowStatus: ["AUDIT", "COMPLETED", "ABORT", "DRAFT"],
        queryType: ["RELATED_ONLY"],
        ...this.queryParams
      }).then(res => {
        this.initTable = res.rows
        this.total = res.total
      })
    },
    handleView(row) {
      this.$router.push({
        name: 'ApproveForms'
      })
      this.$store.commit('SET_PROCEDURE', JSON.stringify({
        templateType: '查看',
        templateName: row.templateName,
        templateId: row.templateId,
        paramsData: {
          ...this.queryParams,
          flowNo: row.flowNo,
          ...row
        },
      }))
    }
  }
}

</script>

<style lang="scss" scoped>
</style>